//
//  MVPCell.m
//  DebugDemo
//
//  Created by XFB on 2018/11/15.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "MVPCell.h"

@interface MVPCell ()

@property (weak, nonatomic) IBOutlet UIButton *plusButton;
@property (weak, nonatomic) IBOutlet UIButton *minusButton;

@end

@implementation MVPCell

/// 减- 按钮点击
- (IBAction)minusButtonDidClick:(UIButton *)sender {
    if ([self.numberLabel.text intValue] <= 0) {
        return;
    }
    self.count --;
}

/// 加+ 按钮点击
- (IBAction)plusButtonDidClick:(UIButton *)sender {

    if ([self.numberLabel.text intValue] >= 500) {
        return;
    }
    self.count ++;
}

- (void)setCount:(int)count
{
    _count = count;
    self.numberLabel.text = [NSString stringWithFormat:@"%d", self.count];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(minusAndPlusButtonDidClickWithCount:indexPath:)]) {
        [self.delegate minusAndPlusButtonDidClickWithCount:self.numberLabel.text indexPath:self.indexPath];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    self.minusButton.layer.cornerRadius = 15;
    self.minusButton.layer.masksToBounds = YES;
    
    self.plusButton.layer.cornerRadius = 15;
    self.plusButton.layer.masksToBounds = YES;
}

@end
